package com.qg.lizhanqi.videosquare.uitlhelp;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

/**
 * Created by zsh2722 on 2016/8/17.
 */
public class ImageCache {
    LruCache<String, Bitmap> mLruCache;

    public ImageCache() {
        initImageCache();
    }

    private void initImageCache() {
        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
        final int cacheSize = maxMemory / 4;
        mLruCache = new LruCache<String, Bitmap>(cacheSize) {
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getRowBytes() * value.getHeight() / 1024;
            }
        };
    }

    // 讲图片存入缓存中
    public void put(String url, Bitmap bitmap) {
        mLruCache.put(url, bitmap);
    }
    // 在缓存中取图片
    public Bitmap get(String url) {
        return mLruCache.get(url);
    }
}
